function loadResources(scripts, stylesheets, timeout, callbackSuccess, callbackFailure) {
    for(var i=0;i<stylesheets.length;i++) {
        var cssNode = document.createElement('link');
        cssNode.type = 'text/css';
        cssNode.rel = 'stylesheet';
        cssNode.href = stylesheets[i].url;
        cssNode.media = 'screen';
        document.createStyleSheet ? document.createStyleSheet(stylesheets[i].url) : document.getElementsByTagName("head")[0].appendChild(cssNode);
    }
    for(var i=0;i<scripts.length;i++) {
        var loaded = false;
        try {
            loaded = eval(scripts[i].test);
        } catch (err) {}
        if(!loaded) {
            var oScript = document.createElement('script');
            oScript.type = 'text/javascript';
            oScript.src = scripts[i].url;
            document.getElementsByTagName("head")[0].appendChild(oScript);
        }
    }
    
    setTimeout(function() {
        checkScriptsTimeout = true;
    }, timeout);
    checkScriptsLoaded(scripts, callbackSuccess, callbackFailure);
}

var checkScriptsTimeout = false;
function checkScriptsLoaded(scripts, callbackSuccess, callbackFailure) {
    if(checkScriptsTimeout) {
        if(typeof callbackFailure === 'function') callbackFailure();
        return;
    }
    var loaded = 0;
    for(var i=0;i<scripts.length;i++) {
        try {
            if(eval(scripts[i].test)) loaded++;
        } catch(err) {}
    }
    if(loaded === scripts.length) {
        if (typeof (callbackSuccess) === 'function') callbackSuccess();
    } else {
        setTimeout(function() {
            checkScriptsLoaded(scripts, callbackSuccess, callbackFailure);
        }, 50);
    }
}

loadResources([{ url: 'https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js', test: 'jQuery' }, { url:'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js', test:'jQuery.ui' },{ url:'http://timer-bookmarklet.googlecode.com/svn/timerbookmarklet.min.js', test:'ti$init' }], [], 10000, function() {
    ti$init();
});
